Transform array of strings in JavaScript